package ${controllerPackageName};

import com.alibaba.dubbo.config.annotation.Reference;

import ${packageName}.${className};
import ${serviceInterfacePackageName}.${className}Service;

import entity.PageResult;
import entity.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
*  @Author ${author}
*  @Email ${email}
*  @Date ${date?string("yyyy-MM-dd HH:mm:ss")}
*/
@RestController
@RequestMapping("/${className?uncap_first}")
public class ${className}Controller {
    @Reference
    private ${className}Service ${className?uncap_first}Service;
    @RequestMapping("/findAll")
    public List<${className}> findAll() {
        return ${className?uncap_first}Service.findAll();
    }
    @RequestMapping("/findPage")
    public PageResult findPage(int pageNum, int pageSize) {
        return ${className?uncap_first}Service.findPage(pageNum,pageSize);
    }
    @RequestMapping("/search")
    public PageResult search(@RequestBody ${className} ${className?uncap_first}, int pageNum, int pageSize) {
        return ${className?uncap_first}Service.findPage(${className?uncap_first},pageNum,pageSize);
    }
    @RequestMapping("/add")
    public Result add(@RequestBody ${className} ${className?uncap_first}) {

        try {
            ${className?uncap_first}Service.add(${className?uncap_first});
            return new Result(true,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"添加失败");
        }
    }
    @RequestMapping("/del")
    public Result del(Long[] ids) {
        try {
            ${className?uncap_first}Service.del(ids);
            return new Result(true,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"删除失败");
        }
    }
    @RequestMapping("/findOne")
    public ${className} findOne(Long id) {
        return ${className?uncap_first}Service.findOne(id);
    }
    @RequestMapping("/update")
    public Result update(@RequestBody ${className} ${className?uncap_first}) {

        try {
            ${className?uncap_first}Service.update(${className?uncap_first});
            return new Result(true,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"修改失败");
        }
    }
}
